package org.hit.burkun.cases.importdb;

import org.hit.burkun.db.DBHelper;
import org.hit.burkun.db.DBTypeConverter;
import org.hit.burkun.dbimport.FileBaseImport;
import org.hit.burkun.file.FileProcessHelper.FILE_TYPE;

public class ImportSinaData extends FileBaseImport{

	public ImportSinaData(String fullFileName, FILE_TYPE fileType,
			String tableName, DBHelper dbHelper, int totalPropertyNum,
			boolean hasAutoIncreasementID, DBTypeConverter typeConverter,
			LINE_SPLITER spliterType) {
		super(fullFileName, fileType, tableName, dbHelper, totalPropertyNum,
				hasAutoIncreasementID, typeConverter, spliterType);
	}

	public static void main(String[] args) {
		importPredictData();
		importTrainData();
		//DBHelper.getServerDataDBHelper().connectionDB();
	}
	
	public static void importTrainData(){
		String fileName = "weibo_train_data.zip";
		final DBHelper dbHelper = DBHelper.getServerDataDBHelper();
		int totalPropertyNum = 8;
		FILE_TYPE fileType = FILE_TYPE.ZIP;
		String tableName = "sina_train";
		boolean hasAutoIncreasementID = true;
		LINE_SPLITER spliterType = LINE_SPLITER.TAB;

		DBTypeConverter.DATATYPE[] types = new DBTypeConverter.DATATYPE[totalPropertyNum];
		types[0] = DBTypeConverter.DATATYPE.I;
		types[4] = DBTypeConverter.DATATYPE.I;
		types[5] = DBTypeConverter.DATATYPE.I;
		types[6] = DBTypeConverter.DATATYPE.I;
		DBTypeConverter typeConverter = new DBTypeConverter(types);
		FileBaseImport imp = new FileBaseImport(fileName, fileType, tableName,
				dbHelper, totalPropertyNum, hasAutoIncreasementID,
				typeConverter, spliterType);
		imp.setBatchImportNumber(10000);
		imp.doImport(1);
	}
	
	public static void importPredictData(){
		String fileName = "weibo_predict_data.zip";
		final DBHelper dbHelper = DBHelper.getServerDataDBHelper();
		int totalPropertyNum = 8;
		FILE_TYPE fileType = FILE_TYPE.ZIP;
		String tableName = "sina_predict";
		boolean hasAutoIncreasementID = true;
		LINE_SPLITER spliterType = LINE_SPLITER.TAB;

		DBTypeConverter.DATATYPE[] types = new DBTypeConverter.DATATYPE[8];
		types[0] = DBTypeConverter.DATATYPE.I;
		types[5] = DBTypeConverter.DATATYPE.I;
		types[6] = DBTypeConverter.DATATYPE.I;
		types[7] = DBTypeConverter.DATATYPE.I;
		DBTypeConverter typeConverter = new DBTypeConverter(types);
		FileBaseImport imp = new ImportSinaData(fileName, fileType, tableName,
				dbHelper, totalPropertyNum, hasAutoIncreasementID,
				typeConverter, spliterType);
		imp.setBatchImportNumber(10000);
		imp.doImport(1);
	}
	@Override
	protected String[] forEachItem(String[] items) {
		if(items[3].length() !=  10){
			return null;
		}
		items[5] = "0";
		items[6] = "0";
		items[7] = "0";
		return items;
	}

}
